﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyMotor : MonoBehaviour
{
    // Start is called before the first frame update
    
    public Vector2 direct;
    public float patrolSpeed,agressiveSpeed,temSpeed;
    public Animator animator;
    private EnemyAI ai;
    void Start()
    {
        direct = Vector2.left;//向左
        patrolSpeed = Random.Range(3, 4);
        agressiveSpeed = Random.Range(4, 6);
        temSpeed = patrolSpeed;

        animator = GetComponent<Animator>();
        animator.SetBool("jump",true);
        ai = GetComponent<EnemyAI>();
    }

    // Update is called once per frame

    public void Move()
    {
        transform.Translate(direct * temSpeed * Time.deltaTime);
    }

    public void ChangeDir()
    { 
            direct *= new Vector2(-1,0);
            transform.Translate(direct * patrolSpeed / 10);
            this.transform.localScale *= new Vector2(-1, 1);
    }

    public void Stop()//停止并播放动画
    {
        temSpeed = 0;
        animator.SetBool("jump",false);
    }
    
}
